
#%%
import os, json

#%%
class MailConfig():
    '''
    数据接口，同mail_config.json
    '''
    def __init__(self, d):
        self.user = d["user"]
        self.passwd = d["password"]

        self.pop_server = d["pop3"]
        self.ssl_pop3_port = None
        if "ssl_pop3_port" in d:
            self.ssl_pop3_port = d["ssl_pop3_port"]
        self.unssl_pop3_port = None
        if "unssl_pop3_port" in d:
            self.unssl_pop3_port = d["unssl_pop3_port"]
        
        try:
            self.smtp_server = d["smtp"]
            self.ssl_smtp_port = None
            if "ssl_smtp_port" in d:
                self.ssl_smtp_port = d["ssl_smtp_port"]
            self.unssl_smtp_port = None
            if "unssl_smtp_port" in d:
                self.unssl_smtp_port = d["unssl_smtp_port"]
        except:
            pass


#%%
class MailConfigParser():
    def __init__(self, mail_config_path):
        with open(mail_config_path, "r") as f:
            self.__mail_config = json.load(f)

    def get(self, mail_name)->MailConfig:
        '''
        mail_name: 与mail.config.json中的名称保持一致，例如"139","sina"等
        '''
        return MailConfig(self.__mail_config[mail_name])
